package P035_AvoidInitializingOtherClassesInConstructors;

import org.junit.Test;

/**
 * @ClassName : AvoidInitializingOtherClassesInConstructors
 * @Description : 避免在构造函数中初始化其他类
 * @Author : wukj1
 * @Date: 2022/3/8 14:13
 **/
public class AvoidInitializingOtherClassesInConstructors {

    @Test
    public void test(){
        Son son = new Son();
        son.doSomething();
    }

    class Father{
        public Father(){
            new Other();
        }
    }

    class Son extends Father{
        public void doSomething(){
            System.out.println("Hi，show me something!");
        }
    }

    class Other{
        public Other(){
            new Son();
        }
    }

}
